package org.nmgyjt.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.nmgyjt.springboot.entity.expert.ExpertInfo;
import org.nmgyjt.springboot.entity.storeInfo.StoreInfo;

import java.util.List;
import java.util.Map;

@Mapper
public interface ExpertMapper extends BaseMapper<ExpertInfo> {
    @Select("SELECT\n" +
            "DISTINCT r.expert_name,r.expert_type,r.phone,r.department," +
            "r.address,r.leveled_name,r.job_level_name,\n" +
            "r.job,r.dsc\n" +
            "FROM\n" +
            "expert_info r LEFT JOIN t_cs_system_source_ext ext ON r.user_id = ext.org_id \n" +
            "LEFT JOIN t_cs_system_admin a ON ext.superior_org_id = a.org_id \n" +
            "WHERE\n" +
            "  a.menu_id = '1000000013' ${sql}")
    List<Map<String,Object>> statisticExpert(String sql);

    @Select("SELECT COUNT(1) FROM (SELECT\n" +
            "ext.source_type\n" +
            "FROM\n" +
            "expert_info r LEFT JOIN t_cs_system_source_ext ext ON r.user_id = ext.org_id \n" +
            "LEFT JOIN t_cs_system_admin a ON ext.superior_org_id = a.org_id \n" +
            "WHERE\n" +
            "a.menu_id = '1000000013' AND a.org_id=#{createdBy, jdbcType=VARCHAR} GROUP BY ext.source_type) t ")
    Integer statisticExpertTypeCount(@Param("createdBy") String createdBy);

    @Select("SELECT \n" +
            "COUNT(1) \n" +
            "FROM \n" +
            "expert_info r LEFT JOIN t_cs_system_source_ext ext ON r.user_id = ext.org_id \n" +
            "LEFT JOIN t_cs_system_admin a ON ext.superior_org_id = a.org_id \n" +
            "WHERE\n" +
            "a.menu_id = '1000000013' AND a.org_id=#{createdBy, jdbcType=VARCHAR}")
    Integer statisticExpertCount(@Param("createdBy") String createdBy);
}
